package com.gmail.bogatyr.alexander.client.presenter;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasValue;
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetDisplay;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

public class TelephoneBookListPresenter extends WidgetPresenter<TelephoneBookListPresenter.Display> {

    public TelephoneBookListPresenter(Display display, EventBus eventBus) {
        super(display, eventBus);
    }

    public interface Display extends WidgetDisplay {
        public HasValue<String> getSearchTextField();
        public HasClickHandlers getSearchButton();
        public HasValue<String> getNumberTextField();
        public HasValue<String> getNameTextField();
        public HasClickHandlers getAddButton();
    }
    
    @Override
    protected void onBind() {
        registerHandler(display.getSearchButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Window.alert("Search contact " + display.getSearchTextField().getValue());
            }
        }));
        registerHandler(display.getAddButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Window.alert("Add contact " + display.getNumberTextField().getValue() + " " 
                        + display.getNameTextField().getValue());
            }
        }));
    }

    @Override
    protected void onUnbind() {
        //nothing
    }

    @Override
    protected void onRevealDisplay() {
        //nothing
    }
}
